package com.sixnimmt.app.shared.game.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

public class Stack implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static final int MAX_CARD_NUMBER = 5;

	private final List<Card> cards;

	protected Stack() {
		cards = new ArrayList<Card>();
	}

	protected void addCard(Card card) {
		cards.add(card);
	}

	protected int getSize() {
		return cards.size();
	}

	protected LinkedHashSet<Card> clearStack() {
		LinkedHashSet<Card> result = new LinkedHashSet<Card>();
		result.addAll(cards);
		cards.clear();
		return result;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for (Card c : cards) {
			sb.append(c + " ");
		}
		return sb.toString();
	}

	public List<Card> getCards() {
		return cards;
	}

	protected int getPointsInStack() {
		int points = 0;
		for (Card card : cards) {
			points += card.getBuffaloHeads();
		}
		return points;
	}

	protected Card getLastCard() {
		return cards.get(cards.size() - 1);
	}

}
